<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
class Autoaddnet extends CI_Controller{    	
    function __construct(){
		parent::__construct();       
	}	
    function index(){
        echo 123;
    }
    function nhandulieu($dh=''){        
        if($dh=='8eebda8718a3'&&$_POST){
            $idnet =$this->input->post('idnet');
            $net = $this->Home_model->get_one('network',array('id'=>(int)$idnet));
            if(!empty($net)){                
                $linkadd=$this->input->post('linkadd');
                $linkadd = str_replace('{Passpb}',$net->pb_pass,$linkadd);
                $linkadd = str_replace('{Idpb}',$net->idpb,$linkadd);//lay dc linh postback chuan                 
                $linkadd = str_replace('codecpa.com/support',$_SERVER['HTTP_HOST'],$linkadd);//lay dc linh postback chuan
                $header_script = str_replace('{pubid}',$this->input->post('pubid'),$this->input->post('header_script'));
                $script = str_replace('{pubid}',$this->input->post('pubid'),$this->input->post('script'));                              
                $data=array(
                    'header_script'=>$header_script,
                    'pb_value'=>$this->input->post('pb_value'),
                    'subid'=>$this->input->post('subid'),
                    'script'=>$script,
                    'rate'=>$this->input->post('rate'),
                    'type'=>$this->input->post('type'),
                    'linkadd'=>$linkadd                
                );
                $this->db->where('id',$net->id);
                $this->db->update('network',$data);
                echo 'Link postback: '.$linkadd;
            }else{
                echo ' Network không tồn tại! nhập id net cho chuẩn!';
            }
        } 
          
    }
    function add($dh=''){
        if($dh=='8eebda8718a3'&&$_POST){
            $data=$_POST;            
            $data['header_script'] = str_replace('{pubid}',$this->input->post('pubid'),$this->input->post('header_script'));
            $data['script'] = str_replace('{pubid}',$this->input->post('pubid'),$this->input->post('script'));
            unset($data['pubid']);                              
            $data['idpb'] = $this->Home_model->select_max('network','idpb')+1;
            $linkadd =$data['linkadd'];
            $linkadd = str_replace('{Passpb}',$data['pb_pass'],$linkadd);
            $linkadd = str_replace('{Idpb}',$data['idpb'],$linkadd);//lay dc linh postback chuan  
            $linkadd = str_replace('codecpa.com/support',$_SERVER['HTTP_HOST'],$linkadd);//lay dc linh postback chuan
            $data['linkadd'] =$linkadd;
            $this->db->insert('network',$data);
            echo 'Link postback: '.$linkadd;            
        } 
               
    }
  
}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */